//
//  PrizeTableCell.m
//  PlayCatchGame
//
//  Created by 流言 on 2018/2/9.
//  Copyright © 2018年 清正. All rights reserved.
//

#import "PrizeTableCell.h"

@interface PrizeTableCell()

/// 中奖状态/选中状态
@property (weak, nonatomic) IBOutlet UIButton *typeNumber;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *typeBtn_right_space;
@property (copy, nonatomic) ButtonBlock buttonBlock;


@end

@implementation PrizeTableCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setTypeText:(NSString *)typeText {
    if (typeText.length>0) {
        _typeText =typeText;
        self.typeBtn_right_space.constant =10.0;
        [self.typeNumber setImage:[UIImage imageNamed:@"clear_action"] forState:UIControlStateNormal];
        [self.typeNumber setTitle:typeText forState:UIControlStateNormal];
    }
}

- (void)setSelectedCell:(BOOL)selectedCell {
    _selectedCell =selectedCell;
    self.typeBtn_right_space.constant =0.0;
    [self.typeNumber setTitle:@"" forState:UIControlStateNormal];
    if (selectedCell) {
        [self.typeNumber setImage:[UIImage imageNamed:@"xuanzhong"] forState:UIControlStateNormal];
    } else {
        [self.typeNumber setImage:[UIImage imageNamed:@"xuanze-moren"] forState:UIControlStateNormal];
    }
}

/// 创建cell
+ (instancetype)findCellWithIdentifier:(NSString*)identifier {
    NSArray *cellArray =[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil];
    for (PrizeTableCell *cell in cellArray) {
        if ([cell.reuseIdentifier isEqualToString:identifier]) {
            return cell;
        }
    }
    return nil;
}

- (IBAction)buttonClick:(id)sender {
    if (self.typeNumber.currentTitle.length ==0) {
        if (self.buttonBlock) {
            self.buttonBlock(sender);
        }
    }
}

- (void)didButtonClickBlock:(ButtonBlock)newBlock {
    self.buttonBlock =newBlock;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
